﻿using System.Text.RegularExpressions;

namespace FileClient.Core.Utils;

public static class EndpointChecker
{
    private static string endPointReg =
        @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]):\d{0,5}$";

    public static bool IsValidFileServer(string fileServerEndpoint)
    {
        if (string.IsNullOrWhiteSpace(fileServerEndpoint))
        {
            throw new Exception("您还没有设置文件服务地址");
        }
        return Regex.IsMatch(fileServerEndpoint, endPointReg);
    }
}